package cn.afactory.tygz.ui.base.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.model.SnsCommentInfo;
import cn.afactory.tygz.model.SnsSubjectDetail;
import cn.afactory.tygz.ui.base.utils.sns.TextUtilListener;
import cn.afactory.tygz.ui.base.views.AutoGridView;
import cn.afactory.tygz.ui.base.views.subject.NearByForumItemView;

/**
 * 附近的事
 */
public class NearByForumsAdapter extends BaseAdapter{

    private List<SnsSubjectDetail> mList = new ArrayList<SnsSubjectDetail>();
    private Context mContext;
    private LayoutInflater mInflater;

    private NearByForumItemView nearByForumItemView;
    private OnItemClickListener mItemClickListener;

    public NearByForumsAdapter(Context context, List<SnsSubjectDetail> dateList) {
        mList = dateList;
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        nearByForumItemView = new NearByForumItemView(mContext);
    }

    public void setItemClickListener(OnItemClickListener listener) {
        mItemClickListener = listener;
        nearByForumItemView.setOnItemClickLsn(listener);
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = nearByForumItemView.bindView(mInflater, parent, mList.get(position), convertView);
        return convertView;
    }

    public void setData(List<SnsSubjectDetail> data) {
        this.mList = data;
        notifyDataSetChanged();
    }

    public interface OnItemClickListener extends TextUtilListener {
        //点赞
        void onPraise(TextView v, SnsSubjectDetail item);
        //点赞
        void onPraise(AutoGridView autoGridView,TextView v, SnsSubjectDetail item);
        //GV大图的点击
        void onClickImage(int position, List<String> mPath);
        //话题点击
        void onClickTopic(String topic, long topicId);
        //分享点击
        void onClickShare(SnsSubjectDetail item);
        //分享点击
        void onClickComment(SnsSubjectDetail item);
        //头像点击
        void onClickIcon(SnsSubjectDetail item);
        //评论头像点击
        void onClickCommentIcon(SnsCommentInfo commentInfo);
        //正文点击
        void onClickTextContent(SnsSubjectDetail item);
        //公司点击
        void onClickCompany(SnsSubjectDetail item);
    }
}
